package model;

import lombok.Data;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.time.LocalDateTime;

/**
 * 键值对数据模型
 * 使用泛型支持不同类型的值
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class KeyValue<T> implements Serializable {
    
    private static final long serialVersionUID = 1L;
    
    /**
     * 键
     */
    private String key;
    
    /**
     * 值（使用泛型支持多种类型）
     */
    private T value;
    
    /**
     * 创建时间
     */
    private LocalDateTime createTime;
    
    /**
     * 更新时间
     */
    private LocalDateTime updateTime;
    
    /**
     * 版本号（用于乐观锁）
     */
    private Long version;
    
    /**
     * 是否删除标记
     */
    private Boolean deleted;
    
    public KeyValue(String key, T value) {
        this.key = key;
        this.value = value;
        this.createTime = LocalDateTime.now();
        this.updateTime = LocalDateTime.now();
        this.version = 1L;
        this.deleted = false;
    }
    
    /**
     * 更新值
     */
    public void updateValue(T newValue) {
        this.value = newValue;
        this.updateTime = LocalDateTime.now();
        this.version++;
    }
    
    /**
     * 逻辑删除
     */
    public void markAsDeleted() {
        this.deleted = true;
        this.updateTime = LocalDateTime.now();
        this.version++;
    }
} 